package com.zp.self.module.date.enum1;

import java.lang.reflect.Method;

/**
 * Created by yanxia.gao on 2018/11/20 17:47
 */
public enum RegionEnum {
    Europe("0", "欧洲"), USA("1", "美国"),
    Coulomb("coulomb", "gal"),Liter("liter", "L"),
    Metric("metric","m³"),Imperial("imperial","yd³");

    private String value;
    private String desc;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    private RegionEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
    *
    *@Description: 根据单位类型(value)取出单位desc,
    *@Author: bingrui.shao
    *@Date: 2020/7/15 14:45
    **/
    public static String getDesc(String value) throws Exception{
        Class<RegionEnum> clzz = RegionEnum.class;
        RegionEnum[] regionEnums = clzz.getEnumConstants();
        Method myValue = clzz.getMethod("getValue");
        Method myDesc = clzz.getMethod("getDesc");
        for (RegionEnum regionEnum:regionEnums){
            if(((String)myValue.invoke(regionEnum)).equals(value)){
                return myDesc.invoke(regionEnum).toString();
            }
        }
        return "";
    }
}
